//
//  Student.m
//  sat10.17_5.6.7.8.9
//
//  Created by dllo on 15/10/17.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "Student.h"

// 7.结构体
void printStudent(Student stu)
{

    printf("%s %c %d %.2f\n", stu.name, stu.sex, stu.number, stu.score);

}

void sortStudentsByNumber(Student stu[], int count)
{

    for (int i = 0; i < count - 1; i++) {
        for (int j = 0; j < count - i - 1; j++) {
            if (stu[j].number > stu[j + 1].number) {
                Student temp = stu[j];
                stu[j] = stu[j + 1];
                stu[j + 1] = temp;
            }
        }
    }
    for (int i = 0; i < count; i++) {
        printStudent(stu[i]);
    }
}

// 9. 高级指针

void printStu(Student *stu)
{

    printf("%s %c %d %.2f\n", (*stu).name, stu->sex, stu->number, stu->score);

}

void sortStuByNumber(Student *stu, int count)
{

    for (int i = 0; i < count - 1; i++) {
        for (int j = 0; j < count - i - 1; j++) {
            if (stu[j].number > (stu + j + 1)->number) {
                Student temp = stu[j];
                stu[j] = stu[j + 1];
                stu[j + 1] = temp;
            }
        }
    }
    for (int i = 0;i < count; i++) {
        printStu(&stu[i]);
    }
}

















